﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Configuration;
using FisheryPlatform.Entity;
using FisheryPlatform.Common.StaticCache;
using FisheryPlatform.Bussiness.Account;
using FisheryPlatform.Bussiness.Cache;

namespace FisheryPlatform.Bussiness.LoginCookie
{
    public struct LoginUserInfo
    {
        /// <summary>
        /// 单用户登录唯一标识，数据库产生;
        /// cookie value缩写 si
        /// </summary>
        public Guid SmartID
        {
            get
            {
                #region
                string value = LoginCookieManager.GetValueFromCookie(CookieKeyConstants.SmartIDConstant);
                if (value != "")
                {
                    return new Guid(value);
                }

                return Guid.Empty;
                #endregion
            }
        }

        /// <summary>
        /// cookie value缩写 ui
        /// </summary>
        public long UserID
        {
            get
            {
                #region
                if (HttpContext.Current.User != null &&
                    HttpContext.Current.User.Identity.IsAuthenticated)
                {
                    return long.Parse(HttpContext.Current.User.Identity.Name);
                }

                //string value = LoginCookieManager.GetValueFromCookie(CookieKeyConstants.UserIDConstant);
                //if (value != "")
                //{
                //    return Convert.ToInt64(value);
                //}

                return 0;
                #endregion
            }
        }

        /// <summary>
        /// cookie value缩写 un
        /// </summary>
        public string LoginName
        {
            get
            {
                #region
                string value = LoginCookieManager.GetValueFromCookie(CookieKeyConstants.UserNameConstant);
                return value;
                #endregion
            }
        }

        /// <summary>
        /// cookie value缩写 rn
        /// </summary>
        public string RealName
        {
            get
            {
                #region
                string value = LoginCookieManager.GetValueFromCookie(CookieKeyConstants.RealNameConstant);
                return value;
                #endregion
            }
        }

        /// <summary>
        /// 网站管理员用户 缓存中
        /// </summary>
        public UsersEntity AdminUserInfo
        {
            get
            {
                var cacheKey = CacheKeyConstants.AdminUserInfoConstant;
                var adminUserInfo = CacheDataUtility.Intance.Get<UsersEntity>(cacheKey);
                if (adminUserInfo == null)
                {
                    adminUserInfo = UserManager.GetUserInfo(1000);
                    CacheDataUtility.Intance.Set(cacheKey, adminUserInfo);
                }
                return adminUserInfo;
            }
        }
    }
}
